package com.yonyou.pmclouds.basecom.conf;

import com.yonyou.pmclouds.basecom.cache.RedisSessionStoreTransfer;
import com.yonyou.yht.cache.redis.RedisPoolFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springside.modules.nosql.redis.JedisTemplate;


@Configuration
public class PMSessionRedisAutoConfiguration {

    @Configuration
    @EnableConfigurationProperties(PMSessionRedisProperties.class)
    protected static class RedisConnectionConfiguration {

        private final PMSessionRedisProperties properties;


        public RedisConnectionConfiguration(PMSessionRedisProperties properties) {
            this.properties = properties;
        }

        @Bean
        public com.yonyou.yht.cache.CacheManager createSessionCacheManager() {
        	
        	JedisTemplate temp = new JedisTemplate(RedisPoolFactory.createJedisPool(properties.getUrl()));
        	com.yonyou.yht.cache.CacheManager cache = new com.yonyou.yht.cache.CacheManager();
        	cache.setJedisTemplate(temp);
        	cache.setSessionTimeout(properties.getSessionTimeout());
        	return cache;
        }

//        @Bean
//        public com.yonyou.iuap.cache.CacheManager createAuthCacheManager() throws UnknownHostException {
//
//        	JedisTemplate temp = new JedisTemplate(RedisPoolFactory.createJedisPool(properties.getUrl()));
//        	com.yonyou.iuap.cache.CacheManager cache = new com.yonyou.iuap.cache.CacheManager();
//        	cache.setJedisTemplate(temp);
//        	return cache;
//        }
        
        
        @Bean
        public RedisSessionStoreTransfer redisCacheTransfer(com.yonyou.yht.cache.CacheManager cache) {
        	RedisSessionStoreTransfer t = new RedisSessionStoreTransfer();
            t.setCacheManager(cache);
            return t;
        }
    }
}
